package ru.spb.osll.myfit.server.parser;

import static org.junit.Assert.*;

import org.junit.Test;

import ru.spb.osll.myfit.common.Include;
import ru.spb.osll.myfit.common.PageElement;

public class IncudeElementParserTest {
  private IncludeElementParser inludeParser = new IncludeElementParser();
  
  @Test
  public void testValideInclude(){
    String line = "!include .MyPage";
    assertTrue(inludeParser.matches(line));
    
    PageElement element = inludeParser.parse(line);
    assertNotNull(element);
    assertTrue(element instanceof Include);
    
    assertEquals(".MyPage", ((Include)element).getPath());
  }
  
  @Test
  public void testMissingPointInPagePathTest(){
    String line = "!include MyPage";
    assertFalse(inludeParser.matches(line));
  }
  
  @Test
  public void testIncludeWithWhiteSpaceCharacters(){
    String line = "!include          .MyPage         ";
    assertTrue(inludeParser.matches(line));
    
    PageElement element = inludeParser.parse(line);
    assertNotNull(element);
    assertTrue(element instanceof Include);
    
    assertEquals(".MyPage", ((Include)element).getPath());
  }
  
  @Test
  public void testIncludeComplexName(){
    String line = "!include  .Parent.Child";
    assertTrue(inludeParser.matches(line));
    
    PageElement element = inludeParser.parse(line);
    assertNotNull(element);
    assertTrue(element instanceof Include);
    
    assertEquals(".Parent.Child", ((Include)element).getPath());
  }
}
